package com.oneinlet

import org.junit.Test
import java.io.BufferedReader
import java.io.File
import java.io.FileInputStream
import java.io.FileReader

/**
 * Created by WangZiHe on 2018/5/19
 * QQ/WeChat:648830605
 * QQ-Group:368512253
 * Blog:www.520code.net
 * Github:https://github.com/yancheng199287
 */
class TestYCStream {
    /**
     *  注意，运行测试用例之前，确保你在C盘根目录下存在文件abc.txt，并且保证有内容，方便后续的测试
     * */
    private val filePath = "C:/abc.txt"
    private val file = File(filePath)

    @Test
    fun testToString() {
        val result = YCStream.toString(FileInputStream(file))
        val result1 = YCStream.toString(BufferedReader(FileReader(file)))
        println(" result: $result \n result1: $result1")
    }

    @Test
    fun testToStringFromWeb() {
        val result = YCStream.toStringFromWeb("http://www.baidu.com")
        println(" result: $result")
    }


    @Test
    fun testToStringFromDisk() {
        val result = YCStream.toStringFromFilePath(filePath)
        val result1 = YCStream.toStringFromFile(file)
        println(" result: $result \n result1: $result1")
    }

    @Test
    fun testAppendContentToFile() {
        val file = File("C:\\Users\\MAC\\Desktop\\test.txt")
        YCStream.appendContentToFile(file, "write best code, became a god!")
    }
}
